<?php
if($sfa <> "" && $bulan <> "" ){
        $cari ="";$page="";$pagination='';
        $num = cal_days_in_month(CAL_GREGORIAN,$bulan,$tahun);
?> 
        
        <div class="table">
                
                <span class=t_judul><?=date("F", mktime(0,0,0,$bulan,1,$tahun)) .' '. $tahun?></span>
                <?php if($bulan < date("n")){?>
                        <input type="button" class="d_copy_journey" bulan="<?=$bulan?>" tahun="<?=$tahun?>" sfa="<?=$sfa?>" value="Copy Journey Cycle To <?=date("F", mktime(0,0,0,date('n'),1,$tahun)) .' '. $tahun?>">
                <?php } ?>
                <span class=t_judul style="text-align: right;">Cari Data: <input type=text name=cari id="n_cari" value="<?=$cari?>"> <input type="button" id="d_cari" value="Cari"> </span>
                <br>&nbsp;
                <table width=100% style="border:solid 1px #aaaaaa;" cellpadding==0 cellspacing==0>
                <thead>
                        <tr height="30px">
                                <th width=30 class="t_header" rowspan=2>No</th>
                                <th width=90 class="t_header" rowspan=2>Kode Outlet</th>
                                <th class="t_header" rowspan=2>Nama Outlet</th>
                                <th width=40 class="t_header" rowspan=2>Outlet Class</th>
                                <th class="t_header" colspan=<?=$num?>>Tanggal</th>
                                <th width=30 class="t_header" rowspan=2>&Sigma;</th>
                        </tr>
                        <tr height="30px">
                                <?php
                                for($t=1;$t<=$num;$t++){
                                        echo'<th class="t_header">'. $t .'</th>';
                                }
                                ?>
                        </tr>
                </thead>
                <tbody>
                        
                        <?php
                        $jumlahkunjungan=0;
                        if($page == "") $page = 1;
                        $i=1 + (15*($page-1));
                        foreach($getJourney as $r){
                                //periksa dulu, pada minggu ini ada yang value-nya = -5 ?, kalo ada, dibuat disab;e
                                $sudah_pindah = "";
                                for($t=1;$t<=$num;$t++){
                                        $nmfield = "d".$t;
                                        if($r->{$nmfield} == -5){
                                                $sudah_pindah .="ada";
                                        }
                                }
                                
                                $idnya = $r->outlet_id;
                                $nama = $r->outlet_name;
                                $territory = $r->terr_out;
                                if($idnya == ""){
                                        $idnya = $r->agent_id;
                                        $nama = $r->agent_name;
                                        $territory = $r->terr_agn;
                                }
                                
                                #ambil Aoutlet Class
                                $kunjungan = $this->mjourney->getJumlahKunjunganSGS($sfa,$tahun.$bulan);
                                $outlet_class = $this->mglobal->showdata('outlet_class','t_history_outlet_class',array('yyyymm'=>$tahun.$bulan,'territory_id'=>$territory),'dblokal');
                                $batas_min = $this->mglobal->showdata('lookup_value','t_mtr_lookup',array('lookup_key'=>'jc_sfa_min','lookup_desc'=>$outlet_class),'dblokal');
                                $bgc = ($kunjungan < $batas_min ? ' style="background-color:yellow;" ':'');
                                //$bgc = ($kunjungan < $batas_min ? ' class="kuning" ':' class="kosong" ');
                                
                                echo'<tr height="30px" '. $bgc .'id="row'.$idnya.'">
                                        <td class="t_isi" align=center>'. $i++ .'</td>
                                        <td class="t_isi">'. ($sudah_pindah==""?$idnya:"<del>".$idnya."</del>") .'</td>
                                        <td class="t_isi" style="text-align: left;">'. ($sudah_pindah==""?$nama:"<del>".$nama."</del>") .'</td>
                                        <td class="t_header">'. $outlet_class .'</td>';
                                        $jml =0;
                                        for($t=1;$t<=$num;$t++){
                                                $nmfield = "d".$t;
                                                $libur = $this->mglobal->showdata('tanggal','t_mtr_holiday',array('tanggal'=>$tahun.$bulan.str_pad($t,2,"0",STR_PAD_LEFT)),'dblokal');
                                                
                                                $weekend = date("N", mktime(0,0,0,$bulan,$t,$tahun));
                                                $bgcolor = "";
                                                #cek hari libur ?
                                                $weekh = $this->mglobal->showdata("d".$weekend,"t_mtr_weekly_holiday",array('type'=>'sfa'),"dblokal");
                                                if($libur <> "" || $weekh == 1){
                                                        $bgcolor=' style="background:#ffb8ad;" ';
                                                }
                                                
                                                // if($bulan < date("n")){
                                                if($bulan < date("n") || (date("d") > $t && $bulan < date("n"))){
                                                        $IMG = "";
                                                        if($r->{$nmfield} == 1){
                                                                $IMG = "<img src='". base_url() ."file/images/semi-ok.png'>";
                                                        }elseif($r->{$nmfield} == -5){
                                                                $IMG = "<img src='". base_url() ."file/images/flag_blue.png'>";
                                                        }
                                                        echo'<td class="t_isi" align=center '. $bgcolor .'>'. $IMG .'</td>';
                                                }else{
                                                        if($r->{$nmfield} == -5){
                                                                $IMG = "<img src='". base_url() ."file/images/flag_blue.png'>";
                                                                echo'<td class="t_isi" align=center '. $bgcolor .'>'. $IMG .'</td>';
                                                        }else{
                                                                $CHECK = $r->{$nmfield} == 1? "checked=checked":"";
                                                                echo'<td class="t_isi" align=center '. $bgcolor .'><input type="checkbox" name="tgl'.$sfa.$t.'" class="d_journey" sfa="'. $sfa .'" tgl="'. $t .'" bulan="'. $tahun.$bulan .'" outlet="'. $idnya .'" '. $CHECK .' ></td>';
                                                        }
                                                }
                                                if($r->{$nmfield} == 1) $jml++;
                                        }
                                echo'<td class="t_isi" align="center"><input type=text readonly=readonly style="border:0px;text-align:center;font-size:10px;" size=1 id="jml_o'.$idnya.'" value='.$jml.'></td>
                                </tr>';
                        }
                        ?>
                <tr height=30>
                        <td colspan=4 class=t_isi><b>Jumlah Kunjungan per Bulan</b></td>
                        <?php
                        for($t=1;$t<=$num;$t++){
                                $kunjungan = $this->mjourney->getTotalKunjunganSGS($sfa, $t, $bulan, $tahun);
                                echo'<td id="jml'.$t.'" class=t_isi align=center>'.$kunjungan.'</td>';
                                $jumlahkunjungan += $kunjungan;
                        }
                        ?>
                        <td class=t_isi align=center><input type=text readonly=readonly style="border:0px;text-align:center;font-size:10px;" size=1 id="jml_total" value=<?=$jumlahkunjungan?> ></a></td>
                </tr>
                </tbody>
                
                </table>
                <div class="pagination ">
                        <div style="float:left;margin:0;padding:0;">
                                <b>Ket:</b>
                                <img src='<?=base_url()?>file/images/semi-ok.png'> Dikunjungi, <img src='<?=base_url()?>file/images/flag_blue.png'> Telah  dipindahkan
                        </div>
                </div>
                <br><br>
                
                <?php if(count($getHoliday)>0){ ?>
                <h4>Information:</h4>
                <ul class="square">
                        <?php
                        foreach($getHoliday as $r){
                                echo"<li><b>". date("M, d Y",mktime(0,0,0,$bulan,substr($r->tanggal,5,2),$tahun)) .":</b> ". $r->keterangan ."</li>";
                        }
                        ?>
                </ul>
                <?php } ?>
        </div>
<?php } ?>

